---
category: Date Time
created: '2020-04-19'
title: Compare two dates
updated: '2021-10-13'
---

**JavaScript version**

```js compare.js
// `a` and `b` are `Date` instances
const compare = (a, b) => a.getTime() > b.getTime();
```

**TypeScript version**

```ts compare.ts
const compare = (a: Date, b: Date): boolean => a.getTime() > b.getTime();
```

**Example**

```js example.js
compare(new Date('2020-03-30'), new Date('2020-01-01')); // true
```
